/**
 * related to nickInput.ui
 * 
 * @Author : wmn1988@qq.com
 * @Timestamp : 2016-07-06
 */

var page = sm("do_Page");
var app = sm("do_App");
var nf = sm("do_Notification");
var hashdata = mm("do_HashData");
var root = ui("$");
var http = require("helper/http");
var imgTool = require("helper/picture");
var urlUser = require("url/user");
var imHelper = require("helper/im");

var userId = null;
var content = null;
var contentNew = "";
//获取上一个页面传入的参数
page.on("loaded", function(){
	var params = page.getData();
	userId = params.id;
	content = params.content;
	ui(addSchool+".textField").text = content;
});

//返回键
page.on("back", function() {
    app.closePage();
});

var headerAout = ui("headerAout");
var addheader = headerAout.add("header", "source://view/reuse/header.ui", 0, 0);
var header = ui("header");
ui(addheader + ".labelTitle").text = "修改毕业学校";
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
    app.closePage();
});

//保存
var headerRight = ui(addheader+".headerRight");
var headerRight_lableNext = ui(addheader+".labelNext");
headerRight_lableNext.text = "保存";
headerRight_lableNext.visible = true;
headerRight.on("touch", function() {
	page.hideKeyboard();
	contentNew = ui(addSchool+".textField").text;
	if(contentNew.trim() == ""){
		nf.toast("请输入修改信息");
		return;
	}
	if(contentNew.trim().length<2){
		nf.toast("学校名称太短了，长度要大于2");
		return;
	}
	submit();
});

function submit(){
	var paramData = {
		id:userId,
		graduateSchool:contentNew
	};
	http.post(urlUser.url.base.doUpdate, paramData, function(data) {
		app.fire("fireUserUpdate",{"logo":"","school":contentNew});
		imHelper.reflashCacheMe();//更新我的信息缓存
		//关闭页面 ，刷新
		app.closePage({"user_update":true});
	});
};



var linearLayout_main = ui("do_LinearLayout_main");

/** -------------------add UI start ---------------------------**/
var addSchool = linearLayout_main.add("school", "source://view/reuse/textField.ui",0,0);
var school = ui("school");
school.bindData(hashdata);
hashdata.addData({
    "textFieldHint":"请输入学校名称"
});
school.refreshData();

var addLine = linearLayout_main.add("line", "source://view/reuse/form/line.ui",0,0);
ui("line").refreshData();
/** -------------------add UI end ---------------------------**/
